﻿@model ComparteTuTiempo.Models.CustomModels.CustomTrabajoMensaje

@using (Ajax.BeginForm("DetalleTrabajo", null, new AjaxOptions
{
    UpdateTargetId = "newMensaje",
    InsertionMode = InsertionMode.Replace,
    //OnBegin = "ajaxValidate",
    OnSuccess = "done",
    //OnSuccess = "validarTexto()",



}, new { id = "formulario" }))
{ 
    <script type="text/javascript">
        //var men = document.getElementById("txtTexto");

        //men.onkeyup = function (e)
        //{
        //        alert("aaaa");
        //        e = e || event;
        //        if (e.keyCode === 13 && !e.ctrlKey) {
        //            alert("aaaa");
        //            this.form.submit();
        //        }

        //    return true;
        //}
        //function validarTexto() {
        //    if (document.getElementById("txtTexto").value != "") {
        //        alert("aaaa");
        //        done();

        //    }
        //}
        function comprobarTexto() {
            if (document.getElementById("txtTexto").value == "") {
                document.getElementById("btnEnviar").disabled = true;
                $("input").keypress(function (evt) {
                    //Deterime where our character code is coming from within the event
                    var charCode = evt.charCode || evt.keyCode;
                    if (charCode == 13) { //Enter key's keycode
                        return false;
                    }
                });
            }
            else {
                document.getElementById("btnEnviar").disabled = false;
            }

        }
    </script>
    <script>
        $(function () {
            $("input").keypress(function (evt) {
                //Deterime where our character code is coming from within the event
                var charCode = evt.charCode || evt.keyCode;
                 
                if (mess == "") { //Enter key's keycode
                    if (charCode == 13 &&  document.getElementById("txtTexto").value=="") {
                        alert("campo vacio");
                        return false;
                    }
                }
            });

        });
    </script>
    <div class="span6">
        Introducir un nuevo mensaje
    </div>
    <div class="">

        @*@Html.TextAreaFor(model => model.mensaje, new { @cols = "60", @rows = "5", @maxlength = "140" })*@
        @*@Html.Editor("texto", null, new { @class="span2" })*@
        <div class="span5">
            @Html.TextBox("texto", null, new { @id = "txtTexto", @class = "span5", @onkeyup = "comprobarTexto();", @onsubmit = "comprobarTexto();" })

        </div>
        <div class="span1">
            <input id="btnEnviar" type="submit" value="Enviar" class="btn" disabled="true" />
        </div>
    </div>
}
@* Funcion JavaScript para cuando se pulse enter, se envie el mensaje. Solo para textarea *@

